﻿public class WeatherData
{
    public DateTime LastCollectionTime { get; set; }
    public double Temperature { get; set; }
    public double Humidity { get; set; }
}

public delegate void DataChangedHandler(WeatherData data);

public class WeatherStation
{
    private WeatherData _data;
    public event DataChangedHandler DataChanged;

    public WeatherStation()
    {
        _data = new WeatherData();
    }

    public void UpdateData(double temperature, double humidity)
    {
        _data.Temperature = temperature;
        _data.Humidity = humidity;
        _data.LastCollectionTime = DateTime.Now;
        OnDataChanged(_data);
    }

    protected virtual void OnDataChanged(WeatherData data)
    {
        DataChanged?.Invoke(data);
    }
}

public class ScreenDisplay
{
    public ScreenDisplay(WeatherStation station)
    {
        station.DataChanged += UpdateDisplay;
    }

    private void UpdateDisplay(WeatherData data)
    {
        Console.WriteLine("=== 屏幕显示更新 ===");
        Console.WriteLine($"时间: {data.LastCollectionTime:yyyy-MM-dd HH:mm:ss}");
        Console.WriteLine($"温度: {data.Temperature}℃");
        Console.WriteLine($"湿度: {data.Humidity}%");
        Console.WriteLine("===================\n");
    }
}

public class DatabaseSaver
{
    public DatabaseSaver(WeatherStation station)
    {
        station.DataChanged += SaveToDatabase;
    }

    private void SaveToDatabase(WeatherData data)
    {
        Console.WriteLine("=== 数据库保存成功 ===");
        Console.WriteLine($"已保存数据 - 时间: {data.LastCollectionTime:yyyy-MM-dd HH:mm:ss}, " +
                          $"温度: {data.Temperature}℃, 湿度: {data.Humidity}%");
        Console.WriteLine("===================\n");
    }
}

class Program
{
    static void Main(string[] args)
    {
        WeatherStation station = new WeatherStation();
        new ScreenDisplay(station);
        new DatabaseSaver(station);

        station.UpdateData(25.6, 60.2);
        System.Threading.Thread.Sleep(2000);
        station.UpdateData(26.1, 58.7);
        System.Threading.Thread.Sleep(2000);
        station.UpdateData(24.9, 62.3);
    }
}